package com.cennavi.minemap.bean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class SourceBean {
	private Integer id;
	private String name;
	private String code;
	private String icon;
	private Integer groupId;
	private String source;
	private String version;
	private Double price;
	private String type;
	private String tileJson;
	private String content;
	private String layerDesc;
	private String describe;
	private Integer uploadId;
	private String createTime;
	private Double minZoom;
	private Double maxZoom;
	private Integer isBind;
	private List<SourceLayerBean> layers;
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public Integer getGroupId() {
		return groupId;
	}
	public void setGroupId(Integer groupId) {
		this.groupId = groupId;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getTileJson() {
		return tileJson;
	}
	public void setTileJson(String tileJson) {
		this.tileJson = tileJson;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getLayerDesc() {
		return layerDesc;
	}
	public void setLayerDesc(String layerDesc) {
		this.layerDesc = layerDesc;
		if(layerDesc != null){
			List<SourceLayerBean> layers = new ArrayList<>();
			JSONArray array = new JSONArray();
			try{
				array = JSONArray.parseArray(layerDesc);
			}
			catch(Exception e){
				System.out.println(layerDesc);
			}
			ObjectMapper m = new ObjectMapper();  
			for(int i = 0 ; i < array.size() ; i++){
				JSONObject object = array.getJSONObject(i);
				try {
					SourceLayerBean layer = m.readValue(object.toJSONString(), SourceLayerBean.class);
					layers.add(layer);
				} catch (JsonParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JsonMappingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			this.layers = layers;
		}
	}
	public String getDescribe() {
		return describe;
	}
	public void setDescribe(String describe) {
		this.describe = describe;
	}
	public Integer getUploadId() {
		return uploadId;
	}
	public void setUploadId(Integer uploadId) {
		this.uploadId = uploadId;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	
	public List<SourceLayerBean> getLayers() {
		return layers;
	}
	public void setLayers(List<SourceLayerBean> layers) {
		this.layers = layers;
	}
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public Double getMinZoom() {
		return minZoom;
	}
	public void setMinZoom(Double minZoom) {
		this.minZoom = minZoom;
	}
	public Double getMaxZoom() {
		return maxZoom;
	}
	public void setMaxZoom(Double maxZoom) {
		this.maxZoom = maxZoom;
	}
	public Integer getIsBind() {
		return isBind;
	}
	public void setIsBind(Integer isBind) {
		this.isBind = isBind;
	}
	
	
//	public static void main(String[] args){
//		SourceBean bean = new SourceBean();
//		String json = 
//				"[                           " + 
//				"	{                          " +
//				"		\"id\" : \"Missingroad\",    " +
//				"		\"attrs\" : [],            " +
//				"		\"name\" : \"缺失道路\",     " +
//				"		\"type\" : \"line\"          " +
//				"	},                         " +
//				"	{                          " +
//				"		\"id\" : \"Construction\",   " +
//				"		\"attrs\" : [],            " +
//				"		\"name\" : \"施工\",         " +
//				"		\"type\" : \"line\"          " +
//				"	},                         " +
//				"	{                          " +
//				"		\"id\" : \"RestricDetail\",  " +
//				"		\"attrs\" : [],            " +
//				"		\"name\" : \"交限\",         " +
//				"		\"type\" : \"symbol\"        " +
//				"	}                          " +
//				"]                           ";
//		
//		bean.setLayerDesc(json);
//		
//		System.out.println(bean);
//	}
}
@JsonIgnoreProperties(ignoreUnknown = true)
class SourceLayerBean{
	private String id;
	private String name;
	private String type;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

}
